// pages/dynasty/dynasty.js

const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    btn: [],
    patbtn: [],
    imgheight: [],
    paint:[],
    btnheight: [],
    text: [],
    btnClick: []
  },

  song1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=13'
    })
  },
  tang1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=5',
    })
  },
  tang2: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=2',
    })
  },
  tang3: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=4',
    })
  },
  tang4: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=8',
    })
  },
  ming1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=1',
    })
  },
  ming2: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=6',
    })
  },
  ming3: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=9',
    })
  },
  ming4: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=10',
    })
  },
  ming5: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=14',
    })
  },
  ming6: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=20',
    })
  },
  ming7: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=21',
    })
  },
  ming8: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=25',
    })
  },
  ming9: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=26',
    })
  },
  ming10: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=27',
    })
  },
  ming11: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=28',
    })
  },
  qing1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=11',
    })
  },
  qing2: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=12',
    })
  },
  wdsg1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=15'
    })
  },
  wdsg2: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=16'
    })
  },
  wdsg3: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=17'
    })
  },
  wdsg4: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=18'
    })
  },
  wdsg5: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=19'
    })
  },
  wdsg6: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=24'
    })
  },
  yuan1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=29',
    })
  },
  yuan2: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=30',
    })
  },
  yuan3: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=31',
    })
  },
  yuan4: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=32',
    })
  },
  mmqc1: function(){
    wx.navigateTo({
      url: '/pages/detail/detail?pId=22',
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var from = options.from;
    var paints = [];
    var patBtn = [];
    var imgHeight = [];
    var btnHeight = [];
    var Btn=[];

    if(from == "song"){
      console.log("song");
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=宋代`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            imgHeight.push('400rpx')
            btnHeight.push("400rpx")
          }
          for(var i=0; i<10; i++){
            if(i<1){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push('none');
              Btn.push('none')
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["song1"]
          })
        },
        fail: err=>{
          console.log(err)
        }
      })
    }else if(from == "yuan"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=元代`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            if(i==1 || i==2){
              imgHeight.push('850rpx')
              btnHeight.push("850rpx")
            }else if(i==0){
              imgHeight.push('200rpx')
              btnHeight.push("200rpx")
            }else if( i==3){
              imgHeight.push('1850rpx')
              btnHeight.push("1850rpx")
            }
          }
          for(var i=0; i<10; i++){
            if(i<4){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["yuan1","yuan2","yuan3","yuan4"]
          })
        }
      })
    }else if(from == "qing"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=清代`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            imgHeight.push('400rpx')
            btnHeight.push("400rpx")
          }
          for(var i=0; i<10; i++){
            if(i<2){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["qing1","qing2"]
          })
        }
      })
    }else if(from == "mmqc"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=明末清初`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            imgHeight.push('800rpx')
            btnHeight.push("800rpx")
          }
          for(var i=0; i<10; i++){
            if(i<1){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["mmqc1"]
          })
        }
      })
    }else if(from == "tang"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=唐代`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            if(i==3){
              imgHeight.push('200rpx')
              btnHeight.push("200rpx")
            }else{
              imgHeight.push('400rpx')
              btnHeight.push("400rpx")
            }
          }
          for(var i=0; i<10; i++){
            if(i<4){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["tang1","tang2","tang3","tang4"]
          })
        }
      })
    }else if(from == "ming"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=明代`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            imgHeight.push('400rpx')
            btnHeight.push("400rpx")
          }
          for(var i=0; i<10; i++){
            if(i<11){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["ming1","ming2","ming3","ming4","ming5","ming6","ming7","ming8","ming9","ming10","ming11"]
          })
        }
      })
    }else if(from == "wdsg"){
      wx.request({
        url: `${app.globalData.url}/painting/?pDynasty=五代十国`,
        success: res=>{
          var arr = res.data.data;
          for(var i=0; i<arr.length; i++){
            paints.push(`${app.globalData.url}/pContent/?pId=${arr[i].pId}`);
            console.log(arr[i].pId)
            if(i==3){
              imgHeight.push('1200rpx')
              btnHeight.push("1200rpx")
            }else if(i==5){
              imgHeight.push('200rpx')
              btnHeight.push("200rpx")
            }else{
              imgHeight.push('400rpx')
              btnHeight.push("400rpx")
            }
          }
          for(var i=0; i<10; i++){
            if(i<6){
              patBtn.push('block');
              Btn.push('flex')
            }else{
              patBtn.push("none");
              Btn.push("none")
            }
          }
          this.setData({
            paint: paints,
            patbtn: patBtn,
            imgheight: imgHeight,
            btnheight: btnHeight,
            btn: Btn,
            btnClick: ["wdsg1","wdsg2","wdsg3","wdsg4","wdsg5","wdsg6"]
          })
        }
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})